﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Kkc.Common;
using Kkc.Application.Specifications;
using Kkc.Model;
using Kkc.Application.Specifications.Announcements;
using System.Web.Mvc;
using Kkc.Application.Controllers;
using System.Web.Security;

namespace Kkc.Application
{
    public abstract class KkcApplication: HttpApplication
    {
        public override void Init()
        {
            InitializeIocContainer();
            InitializeControllers();
        }

        private void InitializeControllers()
        {
            ControllerBuilder.Current.SetControllerFactory(typeof(IocControllerFactory));
        }

        private void InitializeIocContainer()
        {
            var iocContainer = IocContainer.Current as IIocContainer;

            iocContainer.RegisterType<IFormsAuthentication, FormsAuthenticationService>();
            iocContainer.RegisterInstance<MembershipProvider>(Membership.Provider);
            iocContainer.RegisterType<IMembershipService, AccountMembershipService>();
            iocContainer.RegisterInstance<ISpecification<Announcement>>(new NotSpecification<Announcement>(new ExpiredAnnouncementSpecification()), "published");
            iocContainer.RegisterType(typeof(ISpecification<>), typeof(EmptySpecification<>), "published");
        }
    }
}
